package jp.co.withone.gadget.putiputi.base;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

/**
 * ボタン押下時の処理を定義するクラス
 * 
 * @author Sasaki Katsuyuki
 *
 */
public class PutiActionListener extends JFrame implements ActionListener{

	int number;
	URL url;
	ImageIcon icon;
	
	private static int counter=0;
	

	/**
	 * ボタン押下時の処理
	 * 
	 */
	@Override
	public void actionPerformed(ActionEvent e) {

		counter++;
		number = (int)(Math.random()*1000);
		
		JFrame frame = new JFrame();
		Container contentPane = frame.getContentPane();

		PutiBody.frames.add(frame);
		
		JLabel putiLa;
		
		if(number < 51){
			putiLa = new JLabel(counter + "ぷち目");
			frame.setSize(5,50);
			frame.setLocation((int)(PutiBody.dimension.width * Math.random()), (int)(PutiBody.dimension.height * Math.random()));
			
			
		}else if((number > 50 )&& (number < 61)){
			
			url = getClass().getClassLoader().getResource("img/fuchi.jpg");
			icon = new ImageIcon(url);
			putiLa = new JLabel(icon);
			frame.setSize(300,300);
			frame.setLocation((int)(PutiBody.dimension.width * Math.random()), (int)(PutiBody.dimension.height * Math.random()));
			
		}else if (number == 61) {

			url = getClass().getClassLoader().getResource("img/putin.jpg");
			icon = new ImageIcon(url);
			putiLa = new JLabel(icon);
			frame.setSize(PutiBody.dimension.width,PutiBody.dimension.height);
			frame.setLocationRelativeTo(null);

		}else if((number > 61 )&& (number < 66)){

			url = getClass().getClassLoader().getResource("img/welch.jpg");
			icon = new ImageIcon(url);
			putiLa = new JLabel(icon);
			frame.setSize(200,350);
			frame.setLocation((int)(PutiBody.dimension.width * Math.random()), (int)(PutiBody.dimension.height * Math.random()));

		}else if (number==66 || number==67) {

			url = getClass().getClassLoader().getResource("img/obuchi.jpg");
			icon = new ImageIcon(url);
			putiLa = new JLabel(icon);
			frame.setSize(PutiBody.dimension.width,PutiBody.dimension.height);
			frame.setLocationRelativeTo(null);
			
		}else{
			putiLa = new JLabel("ぷち");
			frame.setSize(5,50);
			frame.setLocation((int)(PutiBody.dimension.width * Math.random()), (int)(PutiBody.dimension.height * Math.random()));
		}

		contentPane.add(putiLa);
		
		frame.setResizable(false);
		frame.setVisible(true);
	}
}
